#define _CRT_SECURE_NO_WARNINGS 1
#include"Queue.h"
void QueueInint(Queue* ps) {
	assert(ps);
	ps->phead = ps->ptail = NULL;
	ps->size = 0;
}
void QueueDestroy(Queue* ps) {
	assert(ps);
	QNode* del = ps->phead;
	while (ps->phead)
	{
		del = ps->phead;
		ps->phead = ps->phead->next;
		free(del);
	}
	del = NULL;
	ps->ptail = NULL;
	ps->size = 0;
}

void QueuePush(Queue* ps, QDataType x) 
{
	assert(ps);
	QNode* newNode = (QNode*)malloc(sizeof(QNode));
	newNode->val = x;
	newNode->next = NULL;

	if (ps->ptail == NULL) {
		ps->phead =ps->ptail= newNode;

	}
	else {
		ps->ptail->next = newNode;
		ps->ptail = newNode;
	}
	ps->size++;
}
void QueuePop(Queue* ps) {
	assert(ps);
	QNode* del = ps->phead;
	ps->phead = ps->phead->next;
	free(del);
	del = NULL;
	if (ps->phead == NULL) {
		ps->ptail = NULL;
	}
	ps->size--;
}
QDataType QueueFront(Queue* ps)
{
	assert(ps);
	assert(ps->phead);
	return ps->phead->val;

}
QDataType QueueBack(Queue* ps) {
	assert(ps);
	assert(ps->ptail);
	return ps->ptail->val;
}

bool QueueEmpty(Queue* ps) {
	assert(ps);
	return ps->size == 0;
}	
int Queuesize(Queue* ps) {
	assert(ps);
	return ps->size;
}